wmean <- function(w,x) {
  # weighted mean
 ans <- sum(w * x) / sum(w)
 return(ans)
} # end function wmean

